
import { IStore } from './interface';
import { CookieService } from '@/package/util/browser/cookie.service';
import { ITokenModel } from '../token/interface';


export class CookieStorageStore implements IStore {
    constructor(private srv: CookieService = new CookieService()) {

    }
  
    get(key: string): ITokenModel {
      return JSON.parse(this.srv.get(key) || '{}') || {};
    }
  
    set(key: string, value: ITokenModel | null | undefined): boolean {
      this.srv.put(key, value != null ? JSON.stringify(value) : '{}');
      return true;
    }
  
    remove(key: string): void {
      this.srv.remove(key);
    }
  }
  